package test3;

public class GirlFriendTest {
    public static void main(String[] args) {
        //创建对象
        GirlFriend g1 = new GirlFriend("晓晓",18,"女","唱歌");
        GirlFriend g2 = new GirlFriend("只只",20,"女","跳舞");
        GirlFriend g3= new GirlFriend("依依",21,"女","画画");
        GirlFriend g4 = new GirlFriend("小月",22,"女","逛街");
        //创建数组并存入
        GirlFriend[] arr = {g1,g2,g3,g4};
        //先计算总和，再计算平均值
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i].getAge();
        }
        int avg = sum / arr.length;
        System.out.println("平均年龄为"+avg);
        //遍历进行比较
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].getAge() < avg) {
                count++;
                System.out.println(arr[i].getName() + "," + arr[i].getAge() + "," + arr[i].getGender() + "," + arr[i].getHobby());
            }
        }
            System.out.println("年龄比平均值低的女朋友有"+count+"个");



    }
}
